<?php

Raise::load('core.IRaisePluginHook');

/**
 * TestCoreRaisePlugin
 * Testing unit of 'phpraise/core/RaisePlugin.php', 'phpraise/core/RaisePluginManager.php', 'phpraise/core/IRaisePluginHook.php' and 'phpraise/core/IRaisePluginService.php'
 *
 * @author Sam-Mauris Yong <hellclanner at live dot com>
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.UnitTest.Test
 */
class TestCoreRaisePlugin extends RaiseTest {

    public static function testClass(){
        self::assertClassExists('RaisePlugin');
        self::assertClassExtends('RaisePlugin', 'RaiseObject');
        self::assertClassIsAbstract('RaisePlugin');
        self::assertClassExists('RaisePluginManager');
        self::assertClassExtends('RaisePluginManager', 'RaiseHelper');
        self::assertInterfaceExists('IRaisePluginService');
        self::assertInterfaceExists('IRaisePluginHook');
        self::assertClassExists('MockRaisePluginService');
        self::assertClassImplements('MockRaisePluginService', 'IRaisePluginService');
    }

    public static function testManager(){
        $zip = new RaiseZip('mocks/MockPlugins/TestPlugin-1.0.zip');
        $zip->extract('mocks/MockPlugins/TestPlugin');

        $manager = new RaisePluginManager('mocks/MockPlugins');
        
        self::assertObjectClass($manager, 'RaisePluginManager');
        self::assertStrictEqual($manager->path(), 'mocks/MockPlugins');
        
        self::assertClassExists('TestPlugin');
        self::assertClassExtends('TestPlugin', 'RaisePlugin');
        self::assertClassExists('TestHook');
        self::assertClassImplements('TestHook', 'IRaisePluginHook');

        $manager->registerService('testService', new MockRaisePluginService());

        $c = 'a';
        self::assertStrictEqual($c, 'a');
        $manager->callHook('RaiseTestHook', $c);
        self::assertStrictEqual($c, 'TestPlugin-1.0');
        $manager->removeHook('RaiseTestHook');

        $c = 10;
        self::assertStrictEqual($c, 10);
        $manager->callHook('RaiseTestHookCalcCircle', $c);
        self::assertStrictEqual($c, pi() * 10 * 10);

        $list = $manager->checkUpdates();
        self::assertStrictEqual($list->count(), 1);

        if($list->count() > 0){
            $list->get(0)->update();
        }
    }

}